package com.sunnada.edu.system.sysuser.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sunnada.edu.system.pub.dao.BaseDaoImpl;

@Repository
public class SysUserDaoImpl extends BaseDaoImpl implements SysUserDao {

	@Override
	public int getUserCots(HashMap<String, String> params) {
		List list = selectList("sysuser_sqlmap.getSysUserCots", params);
		if (list != null && list.size() > 0) {
			String cot = ((Map) list.get(0)).get("cot") + "";
			return Integer.valueOf(cot);
		}
		return 0;
	}

	@Override
	public List<?> findUsers(HashMap<String, String> params) {
		return selectList("sysuser_sqlmap.findSysUsers", params);
	}

	@Override
	public int userDelete(HashMap<String, String> params) {
		return delete("sysuser_sqlmap.userDelete", params);
	}

	@Override
	public int userAdd(HashMap<String, String> params) {
		return insert("sysuser_sqlmap.userAdd", params);
	}

	@Override
	public int userUpdate(HashMap<String, String> params) {
		return update("sysuser_sqlmap.userUpdate", params);
	}

	@Override
	public Map getUserByRecId(HashMap<String, String> params) {
		List list = selectList("sysuser_sqlmap.getSysUserByRecId", params);
		if (list != null && list.size() > 0) {
			return (Map) list.get(0);
		}
		return null;
	}

	@Override
	public List<?> findUserEmployeeByUserId(HashMap<String, String> params) {
		return selectList("sysuser_sqlmap.findUserEmployeeByUserId", params);
	}

	@Override
	public List<?> finduserDeveloperByUserId(HashMap<String, String> params) {
		return selectList("sysuser_sqlmap.finduserDeveloperByUserId", params);
	}

	@Override
	public int roleUserAdd(HashMap<String, String> params) {
		return insert("sysuser_sqlmap.roleUserAdd", params);
	}

	@Override
	public int roleUserDelete(HashMap<String, String> params) {
		return delete("sysuser_sqlmap.roleUserDelete", params);
	}

	@Override
	public String[] getRoleIdsByUserId(HashMap<String, String> params) {
		String[] s = new String[2];
		s[0] = "";
		s[1] = "";
		List<?> list = selectList("sysuser_sqlmap.getRoleIdsByUserId", params);
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				if (i != 0) {
					s[0] += ",";
					s[1] += ",";
				}
				s[0] += ((Map) list.get(i)).get("REC_ID");
				s[1] += ((Map) list.get(i)).get("ROLE_NAME");
			}
		}
		return s;
	}

	@Override
	public Map getUserByUserIdNotStatus(HashMap<String, String> params) {
		List list = selectList("sysuser_sqlmap.getUserByUserIdNotStatus", params);
		if (list != null && list.size() > 0) {
			return (Map) list.get(0);
		}
		return null;
	}

	@Override
	public Map<String, String> getUser(HashMap<String, String> params) {
		List list = selectList("sysuser_sqlmap.getUser", params);
		if (list != null && list.size() > 0) {
			return (Map) list.get(0);
		}
		return null;
	}

	@Override
	public int userpasswordUpdate(HashMap<String, String> params) {
		return update("sysuser_sqlmap.userpasswordUpdate", params);
	}

	@Override
	public int userPwdReset(HashMap<String, String> params) {
		return update("sysuser_sqlmap.userPwdReset", params);
	}

	@Override
	public int userEnable(HashMap<String, String> params) {
		return update("sysuser_sqlmap.userEnable", params);
	}

	@Override
	public int userDisable(HashMap<String, String> params) {
		return update("sysuser_sqlmap.userDisable", params);
	}

	@Override
	public int userLogout(HashMap<String, String> params) {
		return update("sysuser_sqlmap.userLogout", params);
	}

	@Override
	public int roleUseLogout(HashMap<String, String> params) {
		return update("sysuser_sqlmap.roleUseLogout", params);
	}

	@Override
	public int userRoleAuthorizeLogout(HashMap<String, String> params) {
		return update("sysuser_sqlmap.userRoleAuthorizeLogout", params);
	}

	@Override
	public String[] getAuthorizeRoleIdsByUserId(HashMap<String, String> params) {
		String[] s = new String[2];
		s[0] = "";
		s[1] = "";
		List<?> list = selectList("sysuser_sqlmap.getAuthorizeRoleIdsByUserId", params);
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				if (i != 0) {
					s[0] += ",";
					s[1] += ",";
				}
				s[0] += ((Map) list.get(i)).get("REC_ID");
				s[1] += ((Map) list.get(i)).get("ROLE_NAME");
			}
		}
		return s;
	}

	@Override
	public int userRoleAuthorizeDelete(HashMap<String, String> params) {
		int num = delete("sysuser_sqlmap.userRoleAuthorizeDelete", params);
		return num;
	}

	@Override
	public int userRoleAuthorizeAdd(HashMap<String, String> param) {
		return insert("sysuser_sqlmap.userRoleAuthorizeAdd", param);
	}

	@Override
	public int userRoleBindDelete(HashMap<String, String> params) {
		return delete("sysuser_sqlmap.userRoleBindDelete", params);
	}

	@Override
	public int userRoleBindAdd(HashMap<String, String> params) {
		return insert("sysuser_sqlmap.userRoleBindAdd", params);
	}

	@Override
	public String[] getNoExitRoleIds(HashMap<String, String> params) {
		String[] s = new String[2];
		s[0] = "";
		s[1] = "";
		List<?> list = selectList("sysuser_sqlmap.getNoExitRoleIds", params);
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				if (i != 0) {
					s[0] += ",";
					s[1] += ",";
				}
				s[0] += ((Map) list.get(i)).get("REC_ID");
				s[1] += ((Map) list.get(i)).get("ROLE_NAME");
			}
		}
		return s;
	}

	@Override
	public String[] getNotAuthorizeRoleIdsByUserId(HashMap<String, String> params) {
		String[] s = new String[2];
		s[0] = "";
		s[1] = "";
		List<?> list = selectList("sysuser_sqlmap.getNotAuthorizeRoleIdsByUserId", params);
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				if (i != 0) {
					s[0] += ",";
					s[1] += ",";
				}
				s[0] += ((Map) list.get(i)).get("ROLE_ID");
				s[1] += ((Map) list.get(i)).get("ROLE_NAME");
			}
		}
		return s;
	}

	@Override
	public int useremployeeDel(HashMap<String, String> params) {
		return delete("sysuser_sqlmap.useremployeeDel", params);
	}

	@Override
	public int useremployeeAdd(HashMap<String, String> params) {
		return insert("sysuser_sqlmap.useremployeeAdd", params);
	}

	@Override
	public int userdeveloperDel(HashMap<String, String> params) {
		return delete("sysuser_sqlmap.userdeveloperDel", params);
	}

	@Override
	public int userdeveloperAdd(HashMap<String, String> params) {
		return insert("sysuser_sqlmap.userdeveloperAdd", params);
	}

	@Override
	public int userEnables(HashMap<String, String> params) {
		return update("sysuser_sqlmap.userEnables", params);
	}

	@Override
	public int userDisables(HashMap<String, String> params) {
		return update("sysuser_sqlmap.userDisables", params);
	}

	@Override
	public List<?> exportSysUser(HashMap<String, String> params) {
		return selectList("sysuser_sqlmap.exportSysUser", params);
	}

	@Override
	public List<?> getRolePower(HashMap<String, String> params) {
		return selectList("sysuser_sqlmap.getRolePower", params);
	}
}
